package com.example.planetexploder.module.picture;

import android.content.Context;
import android.graphics.Bitmap;

import com.example.planetexploder.bean.maindata.BookInfo;
import com.example.planetexploder.bean.maindata.ImgInfo;
import com.example.planetexploder.bean.maindata.ItemInfo;
import com.example.planetexploder.model.dao.Dao;
import com.example.planetexploder.model.folder.Folder;
import com.example.planetexploder.utils.TimeUtil;

import java.io.File;

public class Presenter_ImgProcess {

    private BookInfo bookInfo;
    private ItemInfo itemInfo;
    private ImgInfo imgInfo;
    private Folder folder;
    private Dao dao;

    public Presenter_ImgProcess(Context context, BookInfo bookInfo, ItemInfo itemInfo, ImgInfo imgInfo) {
        this.bookInfo = bookInfo;
        this.imgInfo = imgInfo;
        this.itemInfo = itemInfo;
        this.folder = new Folder(context);
        this.dao = new Dao(context);
    }

    /**
     * 储存图片
     * @param bitmap    图片的bitmap
     */
    public void saveImage( Bitmap bitmap ) {
        folder.imgFile.add_Image_To_ImgGroupFolder(bookInfo.bookId, itemInfo.itemId, imgInfo.imgId, bitmap);
    }

    /**
     * 获得当前图片文件的file
     * @return  图片你的file
     */
    public File getImgFile() {
        return folder.imgFile.get_Image(bookInfo.bookId, itemInfo.itemId, imgInfo.imgId);
    }

    /**
     * 将当前图片添加到数据库中
     */
    public void addImgToDao() {
        dao.imgGroupTable.add_ImgInfo_To_ImgGroupTable(itemInfo.itemId, imgInfo);
        bookInfo.dateMod = TimeUtil.getCurrentTime();
        itemInfo.dateMod = TimeUtil.getCurrentTime();
        dao.bookTable.update_ItemInfo(bookInfo.bookId, itemInfo);
        dao.shelfTable.update_BookInfo(bookInfo);
    }
}
